﻿jQuery(document).ready(function () {

    //jQuery('#transectionAll').datagrid({
    //    url: "/service/api.ashx?metdhodName=GetTransectionDetail",
    //    //        loadFilter: pagerFilter,
    //    //filterBtnIconCls: 'icon-filter'
    //});
    searchTransaction();
});

function pagerFilter(data) {
    if (typeof data.length == 'number' && typeof data.splice == 'function') {	// is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = jQuery(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {
                pageNumber: pageNum,
                pageSize: pageSize
            });
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}

function searchTransaction() {
    var _helper = new Helper();
    var dateFrom = jQuery('#dateFrom').datebox('getValue');
    var dateTo = jQuery('#dateTo').datebox('getValue');
    var plantSrc = jQuery('#plantSrc').val();
    var plantDest = jQuery('#plantDest').val();
    var orderId = jQuery('#orderId').val();
    var productId = jQuery('#productId').val();
    var poId = jQuery('#poId').val();
    var moveType = jQuery('#moveType').val();
    var status = jQuery('#status').combobox('getValue');
    var issueBy = jQuery('#issueBy').combobox('getValue');

    _helper.GetTransection(function (result) {
        jQuery('#transectionAll').datagrid({
            data: result
        });
    },
        dateFrom,
        dateTo,
        plantSrc,
        plantDest,
        orderId,
        productId,
        poId,
        moveType,
        status,
        issueBy);

}


function formatQty(val) {

    if (val < 0) {
        return '<span style="color:red;">(' + val + ')</span>';
    } else {
        return val;
    }
}